﻿using System;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using LiveCharts;
using LiveCharts.Charts;
using LiveCharts.Definitions.Points;
using LiveCharts.Dtos;
using LiveCharts.Wpf.Points;
using LiveCharts.Wpf;
internal class Class12 : PointView, IChartPointView, IStepPointView
{

    public double DeltaX { get; set; }
    public double DeltaY { get; set; }
    internal LineSegment lineSegment { get; set; }
    internal LineSegment lineSegment_1 { get; set; }
    internal Path path { get; set; }
    internal PathFigure pathFigure { get; set; }

    public override void DrawOrMove(ChartPoint previousDrawn, ChartPoint current, int index, ChartCore chart)
    {
        base.ValidArea = new CoreRectangle(current.ChartLocation.X - 7.5, current.ChartLocation.Y - 7.5, 15.0, 15.0);
        this.pathFigure.Segments.Remove(this.lineSegment);
        this.pathFigure.Segments.Remove(this.lineSegment_1);
        if (this.pathFigure.Segments.Count >= index * 2)
        {
            this.pathFigure.Segments.Insert(index * 2, this.lineSegment_1);
            this.pathFigure.Segments.Insert(index * 2 + 1, this.lineSegment);
        }
        base.ValidArea = new CoreRectangle(current.ChartLocation.X - 7.5, current.ChartLocation.Y - 7.5, 15.0, 15.0);
        if (base.IsNew)
        {
            this.lineSegment_1.Point = new Point(current.ChartLocation.X, chart.DrawMargin.Height);
            this.lineSegment.Point = new Point(current.ChartLocation.X, chart.DrawMargin.Height);
            if (this.path != null)
            {
                Canvas.SetLeft(this.path, current.ChartLocation.X - this.path.Width / 2.0);
                Canvas.SetTop(this.path, chart.DrawMargin.Height);
            }
            if (base.DataLabel != null)
            {
                Canvas.SetTop(base.DataLabel, chart.DrawMargin.Height);
                Canvas.SetLeft(base.DataLabel, current.ChartLocation.X);
            }
        }
        if (chart.View.DisableAnimations)
        {
            this.lineSegment_1.Point = new Point(current.ChartLocation.X, current.ChartLocation.Y - this.DeltaY);
            this.lineSegment.Point = new Point(current.ChartLocation.X, current.ChartLocation.Y);
            if (this.path != null)
            {
                Canvas.SetLeft(this.path, current.ChartLocation.X - this.path.Width / 2.0);
                Canvas.SetTop(this.path, current.ChartLocation.Y - this.path.Height / 2.0);
            }
            if (base.DataLabel != null)
            {
                base.DataLabel.UpdateLayout();
                double left = this.FixLeft(current.ChartLocation.X - base.DataLabel.ActualWidth * 0.5, chart);
                double top = this.FixTop(current.ChartLocation.Y - base.DataLabel.ActualHeight * 0.5, chart);
                Canvas.SetLeft(base.DataLabel, left);
                Canvas.SetTop(base.DataLabel, top);
            }
            return;
        }
        TimeSpan animationsSpeed = chart.View.AnimationsSpeed;
        this.lineSegment_1.BeginAnimation(LineSegment.PointProperty, new PointAnimation(new Point(current.ChartLocation.X, current.ChartLocation.Y - this.DeltaY), animationsSpeed));
        this.lineSegment.BeginAnimation(LineSegment.PointProperty, new PointAnimation(new Point(current.ChartLocation.X, current.ChartLocation.Y), animationsSpeed));
        if (this.path != null)
        {
            this.path.BeginAnimation(Canvas.LeftProperty, new DoubleAnimation(current.ChartLocation.X - this.path.Width / 2.0, animationsSpeed));
            this.path.BeginAnimation(Canvas.TopProperty, new DoubleAnimation(current.ChartLocation.Y - this.path.Height / 2.0, animationsSpeed));
        }
        if (base.DataLabel != null)
        {
            base.DataLabel.UpdateLayout();
            double length3 = this.FixLeft(current.ChartLocation.X - base.DataLabel.ActualWidth * 0.5, chart);
            double length4 = this.FixTop(current.ChartLocation.Y - base.DataLabel.ActualHeight * 0.5, chart);
            Canvas.SetLeft(base.DataLabel, length3);
            Canvas.SetTop(base.DataLabel, length4);
        }
    }

    public override void RemoveFromView(ChartCore chart)
    {
        chart.View.RemoveFromDrawMargin(this.path);
        chart.View.RemoveFromDrawMargin(base.DataLabel);
        this.pathFigure.Segments.Remove(this.lineSegment);
        this.pathFigure.Segments.Remove(this.lineSegment_1);
    }

    public override void OnHover(ChartPoint point)
    {
        GStepLineSeries gstepLineSeries = (GStepLineSeries)point.SeriesView;
        if (this.path != null)
        {
            this.path.Fill = this.path.Stroke;
        }
        gstepLineSeries.ShapesStroke.Path_0.StrokeThickness = gstepLineSeries.StrokeThickness + 1.0;
    }

    public override void OnHoverLeave(ChartPoint point)
    {
        GStepLineSeries gstepLineSeries = (GStepLineSeries)point.SeriesView;
        if (this.path != null)
        {
            this.path.Fill = ((point.Fill == null) ? gstepLineSeries.PointForeground : ((Brush)point.Fill));
        }
        gstepLineSeries.ShapesStroke.Path_0.StrokeThickness = gstepLineSeries.StrokeThickness;
    }

    protected double FixLeft(double v, ChartCore chartCore)
    {
        if (v + base.DataLabel.ActualWidth * 0.5 < -0.1)
        {
            return -base.DataLabel.ActualWidth;
        }
        if (v + base.DataLabel.ActualWidth > chartCore.DrawMargin.Width)
        {
            v -= v + base.DataLabel.ActualWidth - chartCore.DrawMargin.Width + 2.0;
        }
        if (v < 0.0)
        {
            v = 0.0;
        }
        return v;
    }

    protected double FixTop(double v, ChartCore chartCore)
    {
        v -= ((this.path == null) ? 0.0 : (this.path.ActualHeight * 0.5)) + base.DataLabel.ActualHeight * 0.5 + 2.0;
        if (v + base.DataLabel.ActualHeight > chartCore.DrawMargin.Height)
        {
            v -= v + base.DataLabel.ActualHeight - chartCore.DrawMargin.Height + 2.0;
        }
        if (v < 0.0)
        {
            v = 0.0;
        }
        return v;
    }
 
  
}
